//
//  MKMainViewController.swift
//  MKWeiBo2017
//
//  Created by nicolas on 2017/5/9.
//  Copyright © 2017年 nicolas. All rights reserved.
//

import UIKit

class MKMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        let composeCallBack = {
            print("Model出控制器")
        }
        
        let mainTabBar = MKMainTabBar()
        mainTabBar.composeCallBack = composeCallBack
        
        setValue(mainTabBar, forKey: "tabBar")
        
        setupChilderViewController()
    }

    func setupChilderViewController() {
        
        let homeVc = MKHomeViewController()
        addChildViewController(controller: homeVc, title: "首页", imageName: "tabbar_home")
        
        let messageVc = MKMessageViewController()
        addChildViewController(controller: messageVc, title: "消息", imageName: "tabbar_message_center")
        
        let discoveryVc = MKDiscoveryViewController()
        addChildViewController(controller: discoveryVc, title: "发现", imageName: "tabbar_discover")
        
        let profileVc = MKProfileViewController()
        addChildViewController(controller: profileVc, title: "我", imageName: "tabbar_profile")
    }
    
    func addChildViewController(controller:UIViewController, title: String, imageName: String) {
        
        controller.title = title
        controller.tabBarItem.image = UIImage(named: imageName)
        
        controller.tabBarItem.selectedImage = UIImage(named: imageName + "_selected")?.withRenderingMode(UIImageRenderingMode.alwaysOriginal)
        
        controller.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orange], for: UIControlState.selected)
        
        self.addChildViewController(UINavigationController(rootViewController: controller))
        
    }


}
